package com.ruoyi.web.controller.shaketicket;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shaketicket.domain.ShaketicketAward;
import com.ruoyi.shaketicket.service.IShaketicketAwardService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 摇一摇奖项 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-01
 */
@Controller
@RequestMapping("/shaketicket/shaketicketAward")
public class ShaketicketAwardController extends BaseController
{
    private String prefix = "shaketicket/shaketicketAward";
	
	@Autowired
	private IShaketicketAwardService shaketicketAwardService;
	
	@RequiresPermissions("shaketicket:shaketicketAward:view")
	@GetMapping()
	public String shaketicketAward()
	{
	    return prefix + "/shaketicketAward";
	}
	
	/**
	 * 查询摇一摇奖项列表
	 */
	@RequiresPermissions("shaketicket:shaketicketAward:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShaketicketAward shaketicketAward)
	{
		startPage();
        List<ShaketicketAward> list = shaketicketAwardService.selectShaketicketAwardList(shaketicketAward);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出摇一摇奖项列表
	 */
	@RequiresPermissions("shaketicket:shaketicketAward:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShaketicketAward shaketicketAward)
    {
    	List<ShaketicketAward> list = shaketicketAwardService.selectShaketicketAwardList(shaketicketAward);
        ExcelUtil<ShaketicketAward> util = new ExcelUtil<ShaketicketAward>(ShaketicketAward.class);
        return util.exportExcel(list, "shaketicketAward");
    }
	
	/**
	 * 新增摇一摇奖项
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存摇一摇奖项
	 */
	@RequiresPermissions("shaketicket:shaketicketAward:add")
	@Log(title = "摇一摇奖项", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShaketicketAward shaketicketAward)
	{		
		return toAjax(shaketicketAwardService.insertShaketicketAward(shaketicketAward));
	}

	/**
	 * 修改摇一摇奖项
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ShaketicketAward shaketicketAward = shaketicketAwardService.selectShaketicketAwardById(id);
		mmap.put("shaketicketAward", shaketicketAward);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存摇一摇奖项
	 */
	@RequiresPermissions("shaketicket:shaketicketAward:edit")
	@Log(title = "摇一摇奖项", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShaketicketAward shaketicketAward)
	{		
		return toAjax(shaketicketAwardService.updateShaketicketAward(shaketicketAward));
	}
	
	/**
	 * 删除摇一摇奖项
	 */
	@RequiresPermissions("shaketicket:shaketicketAward:remove")
	@Log(title = "摇一摇奖项", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(shaketicketAwardService.deleteShaketicketAwardByIds(ids));
	}
	
}
